<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
use yii\widgets\Pjax;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\GkyProfileSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Gky Profiles';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="gky-profile-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <div class="col-md-12">      
        <?php
        $form = ActiveForm::begin([
                    'action' => ['index'],
                    'method' => 'get',
                    'options' => ['class' => 'input-group'],
                    'fieldConfig' => [
                        'template' => '<div class="col-lg-12">{input}</div>',
                    ]
                ])
        ?>

        <div class="col-md-10">
            <label style="float: left;margin-top: 5px;">姓名</label>
            <div style="overflow: hidden;">
                <?php
//                $data = app\models\GkyProfile::find()->all();
//                echo $form->field($searchModel, 'name')->widget(Select2::classname(), [
//                    'data' => ArrayHelper::map($data, 'name', 'name'),
//                    'options' => ['placeholder' => '请输入内容'],
//                    'pluginOptions' => [
//                        'allowClear' => true
//                    ],
//                ]);
                ?>
                 <?php
                $projects = app\models\GkyProfile::find()->all();
                foreach ($projects as $item) {
                    $source[] = $item->name;
                }
                echo yii\jui\AutoComplete::widget([
                    'model' => $searchModel,
                    'attribute' => 'name',
                    'options'=>['style'=>'margin-left:10px'],
                    'clientOptions' => [
                        'source' => $source,
                    ],
                ]);
                ?>       
            </div>
        </div>

        <div class="col-md-2 text-center">
            <?= Html::submitButton('搜索', ['class' => 'btn btn-primary']) ?> 
        </div>

    </div>

    <div class="col-md-12 text-right" style="margin: 15px 0 15px 15px;">
    </div>

    <?php ActiveForm::end(); ?>    
    <?php Pjax::begin(); ?>
    <?=
    GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            [
                'attribute' => 'name',
                'label' => '姓名',
                'format' => 'raw',
                'value' => function ($model) {
                    //判断是否绑定企业微信号
                    return $model->name ? $model->name : $model->user->username;
                },
                'contentOptions' => ['style' => ''],
                'headerOptions' => ['style' => ''],
            ],
            'gravatar_email',
//            'qyh_user_id',
            [
                'attribute'=>'qyh_user_id',
                'format' => 'raw',
                'value'=>  function ($model){
                    return $model->qyhUser?$model->qyhUser->name.'（'.$model->qyhUser->userid.'）':'<em>未绑定</em>';
                }
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'urlCreator' => function($action, $model, $key, $index) {
                    return \yii\helpers\Url::toRoute(['gky-profile/view', 'id' => $key]);
                },
                        'template' => '{view}',
                        'buttons' => [
                            //view button
                            'view' => function ($url) {
                                return Html::a('<span class="fa fa-search"></span>详细', $url, [
                                            'title' => Yii::t('app', 'View'),
//                                    'class' => 'btn btn-primary btn-xs',
                                ]);
                            },
                                ],
                            ],
                        ],
                    ]);
                    ?>
                    <?php Pjax::end(); ?>
</div>
